package com.rongma.waterdrop.network.api;

import android.content.Context;

import com.rongma.waterdrop.listener.getBmob.GetAllUserListener;
import com.rongma.waterdrop.model.User;
import com.rongma.waterdrop.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

/**
 * 从Bmob云后台获取所有User数据
 * Created by RongMa on 16/6/5.
 */

public class GetAllUserAPI
{
    private GetAllUserListener listener;

    public GetAllUserAPI(GetAllUserListener listener)
    {
        this.listener = listener;
    }

    //从网络获取所有的User数据
    public void getDataFromBmob(final Context context)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                BmobQuery<User> userBmobQuery = new BmobQuery<User>();
                userBmobQuery.findObjects(context, new FindListener<User>() {
                    @Override
                    public void onSuccess(List<User> list) {
                        LogUtils.show("获取数据成功!"+list.size()+"个");
                        listener.onSuccess((ArrayList<User>) list);
                    }

                    @Override
                    public void onError(int i, String s){
                        listener.onError(s);
                    }
                });

            }
        }).start();
    }

}
